package com.zmn.plat.services.impl.product.graphic;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.product.graphic.ProductGraphic;
import com.zmn.plat.model.entity.product.graphic.ProductGraphicQuery;
import com.zmn.plat.persistence.interfaces.product.graphic.ProductGraphicDao;
import com.zmn.plat.services.interfaces.product.graphic.ProductGraphicService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 描述: 产品图文接口实现类
 *
 * @author yangshuangping
 * @since 2021/12/09 17:41
 */
@Slf4j
@Service
public class ProductGraphicServiceImpl implements ProductGraphicService {

    private static final String TAG = "产品图文基础服务接口";

    @Resource
    private ProductGraphicDao productGraphicDao;

    @Override
    public ProductGraphic findById(Integer graphicId) {

        if (Objects.isNull(graphicId)) {
            log.error("[{}],根据id查询数据graphicId为null", TAG);
            return null;
        }
        return productGraphicDao.findById(graphicId);
    }

    @Override
    public List<ProductGraphic> listByIds(List<Integer> graphicIds) {

        if (CollectionUtils.isEmpty(graphicIds)) {
            log.error("[{}],按条件查询数据,graphicIds为null", TAG);
            return null;
        }
        return productGraphicDao.listByIds(graphicIds);
    }

    @Override
    public List<ProductGraphic> listByQuery(ProductGraphicQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        return productGraphicDao.listByQuery(query);
    }

    @Override
    public List<ProductGraphic> listPageByQuery(ProductGraphicQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        query.setTotalCount(productGraphicDao.countByQuery(query));
        return productGraphicDao.listPageByQuery(query);
    }

    @Override
    public Integer countByQuery(ProductGraphicQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return null;
        }
        return productGraphicDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(ProductGraphic productGraphic) {

        if (Objects.isNull(productGraphic.getGraphicId())) {
            log.error("[{}],根据id修改数据,productGraphic为null", TAG);
            return null;
        }
        return productGraphicDao.updateByKey(productGraphic);
    }

    @Override
    public void updateStatusBatch(List<Integer> ids, Integer status, String operator) {

        if (!Objects.equals(status, GlobalConsts.NO) && !Objects.equals(status, GlobalConsts.YES)) {
            log.error("[{}],status状态超出取值范围", TAG);
            return;
        }
        productGraphicDao.updateStatusBatch(ids, status, operator, DateUtil.getNow());
    }

    @Override
    public Integer insert(ProductGraphic productGraphic) {

        if (Objects.isNull(productGraphic)) {
            log.error("[{}],新增数据,productGraphic为null", TAG);
            return null;
        }
        return productGraphicDao.insert(productGraphic);
    }

    @Override
    public void insertBatch(List<ProductGraphic> list) {

        if (CollectionUtils.isEmpty(list)) {
            log.error("[{}],数据为空", TAG);
            return;
        }
        productGraphicDao.insertBatch(list);
    }

    @Override
    public Integer deleteByKey(Integer graphicId) {

        if (Objects.isNull(graphicId)) {
            log.error("[{}],根据id删除数据,graphicId为null", TAG);
            return null;
        }
        return productGraphicDao.deleteByKey(graphicId);
    }

}